﻿using EasyBuyShop.DAL;
using Microsoft.AspNetCore.Mvc;

namespace EasyBuyShop.Controllers
{
    public class ProductController : Controller
    {
        private readonly ILogger<ProductController> logger;

        public ProductController(ILogger<ProductController> logger)
        {
            this.logger = logger;
        }

        public IActionResult Index(int categoryId,int subCategoryId,string productName)
        {
            var username = HttpContext.Session.GetString("username");
            var realName = HttpContext.Session.GetString("realname");
            ViewData["Username"] = username;
            ViewData["RealName"] = realName;
            ProductDal productDal = new ProductDal();
            var productList= productDal.GetProductList(categoryId, subCategoryId, productName);
            ViewData["ProductList"]= productList;
            return View();
        }

        public IActionResult Detail(int Id)
        {
            var username = HttpContext.Session.GetString("username");
            var realName = HttpContext.Session.GetString("realname");
            ViewData["Username"] = username;
            ViewData["RealName"] = realName;
            ProductDal productDal = new ProductDal();
            ProductConfigDal productConfigDal = new ProductConfigDal();
            var product = productDal.GetProduct(Id);
            var productConfigList = productConfigDal.GetProductConfigListById(Id);
            ViewData["ProductConfigList"]=productConfigList;
            ViewData["Product"] = product;
            return View();
        }
    }
}
